<script setup>
import { ref, onMounted } from 'vue'
import { useToast } from 'wot-design-uni'
import { useLivePusherStoreHook } from '@/stores/modules/livePusher'
import { useUserStoreHook } from '@/stores/modules/user'

const toast = useToast()

const useUserStore = useUserStoreHook()
const useLivePusherStore = useLivePusherStoreHook()
const openLiveBroadcast = ref(null)

const init = () => {
	openLiveBroadcast.value = {}
}

// 选择的直播间
const optionLiveBroadcast = (itme) => {
	openLiveBroadcast.value = itme
}

// 打开直播
const openLiveBroadcastOn = () => {
	if(!openLiveBroadcast.value) {
		toast.show('请求选择直播间')
		return
	}
	
	const livePusherData = {
		user_id: useUserStore.userinfo.id,
		account: useUserStore.userinfo.account,
		nickname: useUserStore.userinfo.nickname,
		live_broadcast_id: openLiveBroadcast.value.id,
		live_broadcast_name: openLiveBroadcast.value.live_broadcast_name,
		live_broadcast_room: openLiveBroadcast.value.live_broadcast_room,
		live_broadcast_poster: openLiveBroadcast.value.live_broadcast_poster
	}
	
	// #ifdef APP-PLUS
	uni.navigateTo({
		url: `/pages/live-pusher/live-pusher?userData=${JSON.stringify(livePusherData)}`
	});
	// #endif
	
	// #ifdef H5
	toast.show('H5不支持直播')
	// #endif
}

const getWindowHeight = () => {
	const res = uni.getSystemInfoSync()
	return res.windowHeight
}

</script>

<template>
	<view class="open-live-broadcast-page" :style="`height: ${getWindowHeight()}px;`">
		<view class="live-broadcast-list">
			<view
				class="live-broadcast-itme"
				:key="itme.id"
				@click="optionLiveBroadcast(itme)"
				v-for="itme in useLivePusherStore.liveBroadcastList">
				<view class="itme-data itme-data1">
					<image
						class="itme-img"
						mode="aspectFit"
						:src="itme.live_broadcast_poster"></image>
				</view>
				<view class="itme-data itme-data2">{{ itme.live_broadcast_name }}</view>
				<view class="itme-data itme-data3">{{ itme.live_broadcast_room }}</view>
			</view>
		</view>
		<view class="open-live-broadcast-box">
			<view class="open-live-broadcast-itme o-l-b-b">
				<view class="o-l-b-i">
					<image
						class="live-broadcast-poster-img"
						v-if="openLiveBroadcast"
						:src="openLiveBroadcast.live_broadcast_poster"
						mode="aspectFit">
					</image>
				</view>
				<view class="o-l-b-i user-text">
					<image
						class="user-itme-img"
						v-if="openLiveBroadcast"
						:src="useUserStore.userinfo.avatar" mode=""></image>
					<view
						v-if="openLiveBroadcast"
						class="user-text-itme">用户: {{ useUserStore.userinfo.nickname }}</view>
					<view
						class="user-text-itme" 
						v-if="openLiveBroadcast">名称: {{ openLiveBroadcast.live_broadcast_name }}</view>
					<view
						class="user-text-itme" 
						v-if="openLiveBroadcast">直播号: {{ openLiveBroadcast.live_broadcast_room }}</view>
					<view
						class="user-text-itme" 
						v-if="openLiveBroadcast">创建时间: {{ openLiveBroadcast.created_at }}</view>
					<view
						class="user-text-itme" 
						v-if="openLiveBroadcast">
						<wd-tag custom-class="itme-space">
							{{ openLiveBroadcast.status ? '已禁止' : '未禁止' }}
						</wd-tag>
						<wd-tag custom-class="itme-space">
							{{ openLiveBroadcast.is_public ? '私密' : '公开'  }}
						</wd-tag>
					</view>
				</view>
			</view>
			<view class="open-live-broadcast-itme open-live-broadcast-icon">
				<view class="l-b-icon" @click="openLiveBroadcastOn"></view>
			</view>
		</view>
	</view>
	<wd-toast />
</template>

<style scoped lang="scss">
@import "@/common/common.scss";
	
.open-live-broadcast-page {
	width: 100%;
	
	.live-broadcast-list {
		width: 100%;
		height: 400rpx;
		overflow-y: scroll;
		border-bottom: 1px solid #5B5E66;
		
		.live-broadcast-itme {
			width: 90%;
			height: 120rpx;
			margin: 10rpx auto;
			border-radius: 10rpx;
			background-color: $all-box-bg-color;
			
			display: flex;
			
			.itme-data {
				color: #dddddd;
				margin: 0 10rpx;
				line-height: 120rpx;
				
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}
			
			.itme-data1 {
				width: 10%;
				.itme-img {
					width: 100%;
					height: 100%;
				}
			}
			.itme-data2 {
				width: 60%;
			}
			.itme-data3 {
				width: 30%;
			}
		}
	}
	
	.open-live-broadcast-box {
		width: 100%;
		height: 67%;
		
		display: flex;
		flex-direction: column;
		
		.open-live-broadcast-itme {
			flex: 1;
		}
		.o-l-b-b {
			margin-top: 10rpx;
			padding-bottom: 10rpx;
			border-bottom: 1px solid #5B5E66;
			
			display: flex;
			
			.o-l-b-i {
				width: 50%;
				height: 100%;
				
				.live-broadcast-poster-img {
					width: 100%;
					height: 100%;
				}
			}
			.user-text {
				display: flex;
				flex-direction: column;
				align-items: flex-start;
				justify-content: flex-start;
				border-left: 1px solid #5B5E66;
				
				.user-text-itme {
					width: 100%;
					height: 50rpx;
					color: #dddddd;
					font-size: 28rpx;
					margin: 5rpx 0 0 10rpx;
					
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					
					:deep(.itme-space) {
						margin-right: 10rpx;
					}
				}
				.user-itme-img {
					margin: 10rpx;
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
				}
			}
		}
		
		.open-live-broadcast-icon {
			display: flex;
			align-items: center;
			justify-content: center;
			
			.l-b-icon {
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
				border: 3px solid #dddddd;
				background-color: #f00;
			}
		}
	}
}
</style>
